package com.liuche.homechat.common.user.controller;

import com.liuche.homechat.common.common.enums.BusinessTypeEnum;
import com.liuche.homechat.common.user.annotation.Permission;
import com.liuche.homechat.common.user.domain.vo.req.user.BlackReq;
import com.liuche.homechat.common.user.domain.vo.req.user.ModifyNameReq;
import com.liuche.homechat.common.user.domain.vo.req.user.WearingBadgeReq;
import com.liuche.homechat.common.user.domain.vo.resp.user.BadgeResp;
import com.liuche.homechat.common.user.domain.vo.resp.user.UserInfoResp;
import com.liuche.homechat.common.user.enums.ItemEnum;
import com.liuche.homechat.common.user.enums.ItemTypeEnum;
import com.liuche.homechat.common.common.model.vo.resp.ApiResult;
import com.liuche.homechat.common.common.utils.RequestHolder;
import com.liuche.homechat.common.user.service.UserBackpackService;
import com.liuche.homechat.common.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author <a href="https://github.com/0liu0">liuche</a>
 * @since 2023-10-29
 */
@RestController
@RequestMapping("/capi/user")
@Api(tags = "用户信息")
public class UserController {
    @Resource
    private WxMpService wxMpService;
    @Resource
    private UserBackpackService userBackpackService;

    @Resource
    private UserService userService;
    @GetMapping("/test")
    public ApiResult<String> testGet() {
        userBackpackService.acquireItem(20006L, ItemTypeEnum.BADGE, BusinessTypeEnum.ACQUIRE_BADGE.getType().longValue(), ItemEnum.PLANET.getId());
        return ApiResult.success("你好👋，欢迎使用花生壳内网穿透工具！");
    }

    @GetMapping("/userInfo")
    @ApiOperation("用户详情")
    public ApiResult<UserInfoResp> getUserInfo() {
        return ApiResult.success(userService.getUserInfo(RequestHolder.get().getUid()));
    }

//    @PostMapping("/public/summary/userInfo/batch")
//    @ApiOperation("用户聚合信息-返回的代表需要刷新的")
//    public ApiResult<List<SummeryInfoDTO>> getSummeryUserInfo(@Valid @RequestBody SummeryInfoReq req) {
//        return ApiResult.success(userService.getSummeryUserInfo(req));
//    }
//
//    @PostMapping("/public/badges/batch")
//    @ApiOperation("徽章聚合信息-返回的代表需要刷新的")
//    public ApiResult<List<ItemInfoDTO>> getItemInfo(@Valid @RequestBody ItemInfoReq req) {
//        return ApiResult.success(userService.getItemInfo(req));
//    }

    @PutMapping("/name")
    @ApiOperation("修改用户名")
    public ApiResult<Void> modifyName(@Valid @RequestBody ModifyNameReq req) {
        userService.modifyName(RequestHolder.get().getUid(), req);
        return ApiResult.success();
    }

    @GetMapping("/badges")
    @ApiOperation("可选徽章预览")
    public ApiResult<List<BadgeResp>> badges() {
        return ApiResult.success(userService.badges(RequestHolder.get().getUid()));
    }

    @PutMapping("/badge")
    @ApiOperation("佩戴徽章")
    public ApiResult<Void> wearingBadge(@Valid @RequestBody WearingBadgeReq req) {
        userService.wearingBadge(RequestHolder.get().getUid(), req);
        return ApiResult.success();
    }

    @PutMapping("/black")
    @ApiOperation("拉黑用户")
    @Permission
    public ApiResult<Void> pushBlack(@Valid @RequestBody BlackReq req) {
        userService.pushBlack(req);
        return ApiResult.success();
    }
}

